package com.example.springboot.dao;

import com.example.springboot.pojo.User;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@Repository
public class UserDao {
    private static Map<Integer, User> users = null;

    static {
        users = new HashMap<>();
        users.put(1,new User(1,"haha1",1));
        users.put(2,new User(2,"haha2",1));
        users.put(3,new User(3,"haha3",1));
        users.put(4,new User(4,"haha4",1));
        users.put(5,new User(5,"haha5",0));
        users.put(6,new User(6,"haha6",0));
    }

    public Collection<User> getAll(){
        return users.values();
    }

    public void addUser(User user){
        users.put(user.getId(),user);
    }

    public User getUser(Integer id) {
        return users.get(id);
    }

    public int updateUser(User user) {
        users.remove(user.getId());
        users.put(user.getId(),user);
        return 1;
    }

    public int removeUser(Integer id) {
        users.remove(id);
        return 1;
    }
}
